"""
created  by  hzwlxy  at 2018/7/4 10:42
__author__: 西瓜哥
__QQ__ : 120235331
__Note__： 角色表
"""


__author__ = '西瓜哥'

from app.ext import db
from app.models.base import Base

role_permission = db.Table(
    "role_permission",
    db.Column('permission_id', db.Integer, db.ForeignKey('permissions.id'), primary_key=True),
    db.Column('role_id', db.Integer, db.ForeignKey('roles.id'), primary_key=True),
)


class Role(Base):
    """
    角色表
    """
    __tablename__ = "roles"

    name = db.Column(db.String(length=20), nullable=False, comment="角色名", unique=True)
    label = db.Column(db.String(length=50), nullable=False, comment="角色介绍", unique=True)

    permissions = db.relationship('Permission', backref="roles", lazy="dynamic", secondary=role_permission)
